﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace Simhopp.Common
{
    [Serializable]
    /// <summary>
    /// The UserInfo class provides the credentials of a user (password not included).
    /// </summary>
    public class UserInfo : ISerializable
    {
        #region FIELD REGION
        private String username;
        private Credentials credentials = new Credentials();
        #endregion
        #region CONSTRUCTOR REGION
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="username"></param>
        /// <param name="name"></param>
        /// <param name="gender"></param>
        /// <param name="age"></param>
        /// <param name="nationality"></param>
        public UserInfo(String username = "", 
            String name = "", 
            Genders gender = Genders.DEFAULT,
            int age = 0, 
            String nationality = "")
        {
            this.username = username;
            credentials.Name = name;
            credentials.Gender = gender;
            credentials.Age = age;
            credentials.Nationality = nationality;
        }
        #endregion
        #region PROPERTY REGION
        /// <summary>
        /// Property Username gets or sets the username field.
        /// </summary>
        public String Username
        {
            get { return username; }
            set { username = value; }
        }
        /// <summary>
        /// Property Name gets or sets the name field.
        /// </summary>
        public String Name
        {
            get { return credentials.Name; }
            set { credentials.Name = value; }
        }
        /// <summary>
        /// Property Gender gets or sets the gender field.
        /// </summary>
        public Genders Gender
        {
            get { return credentials.Gender;}
            set { credentials.Gender = value; }
        }
        /// <summary>
        /// Property Age gets or sets the age field.
        /// </summary>
        public int Age
        {
            get { return credentials.Age; }
            set { credentials.Age = value; }
        }
        /// <summary>
        /// Property Nationality gets or sets the nationality field.
        /// </summary>
        public String Nationality
        {
            get { return credentials.Nationality; }
            set { credentials.Nationality = value; }
        }
        #endregion
        #region SERIALIZE/DESERIALIZE REGION
        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("Username", username, typeof(String));
            info.AddValue("Credentials", credentials, typeof(Credentials));
        }
        protected UserInfo(SerializationInfo info, StreamingContext context)
        {
            username = (String)info.GetValue("Username", typeof(String));
            credentials = (Credentials)info.GetValue("Credentials", typeof(Credentials));
        }
        #endregion
    }
}
